package com.yunxi.module.system.service.mail.impl;

import com.google.common.annotations.VisibleForTesting;
import com.yunxi.module.system.model.mail.MailAccountDO;
import com.yunxi.module.system.mq.message.mail.MailSendMessage;
import com.yunxi.module.system.service.mail.MailAccountService;
import com.yunxi.module.system.service.mail.MailSendService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;

import javax.annotation.Resource;

/**
 * <p>
 * 邮件发送 Service 接口实现类、
 * </p>
 *
 * @author lidy
 * @since 2024-05-08
 */
@Service
@Validated
@Slf4j
public class MailSendServiceImpl implements MailSendService {

    @Resource
    private MailAccountService mailAccountService;

    /**
     * 执行邮件发送
     * 注意：该方法仅提供给 MQ Consumer 使用
     *
     * @param message 邮件
     */
    @Override
    public void doSendMail(MailSendMessage message) {
        // 1. 创建发送账号
        MailAccountDO accountDO = validateMailAccount(message.getAccountId());

    }

    /**
     * 校验发送账号
     *
     * @param accountId 发送账号编号
     * @return 发送账号信息
     */
    @VisibleForTesting
    private MailAccountDO validateMailAccount(Long accountId) {
        // 获得邮箱账号。考虑到效率，从缓存中获取
        MailAccountDO accountDO = mailAccountService.getMailAccountFromCache(accountId);

        return null;
    }
}
